Skip to content

[2.0] feat(data-insights): add the DataInsightsExtension hook (backport of #33079's hook) - #37815

Merged
pmbrull merged 1 commit into
2.0from
backport/2.0/data-insights-extension-hook
Nov 15, 2026
Merged

pmbrull merged 1 commit into
2.0from
backport/2.0/data-insights-extension-hook

Conversation

@pmbrull

@pmbrull pmbrull commented Nov 14, 2026

Copy link
Copy Markdown
Member

Describe your changes:

Backport of the Data Insights extension hook from #33079 to 2.0. This carries existing main code to 2.0, so no separate issue is linked.

On main, DataAssetsWorkflow opens every DataInsightsExtension that ServiceLoader finds for a Data Insights run, and each one can add fields to the snapshot documents. 2.0 has no such hook, so a distribution built on 2.0 cannot add a field to the Data Insights snapshot without patching the workflow. This PR adds the hook and nothing else from #33079:

  • DataInsightsExtension: the SPI, the same as on main except that 2.0's EntityInterface is not generic.
  • DataInsightsExtensions: opens every provider for one run and closes them on a failed start or at the end.
  • DataAssetsWorkflow: calls beforeBatch before each batch is enriched, enrich on each snapshot document, and complete after a run that neither stopped nor failed. The calls sit where main has them.

Everything else in #33079 is left out: the completeness evidence, the index-template fields, the search-client changes and the failure-reporting changes. So is main's diRunId/diCapturedAt stamp on every document. 2.0's index template has no mapping for those two fields, so dynamic mapping would add them to every Data Insights document as new fields.

OpenMetadata registers no provider, so an OSS run does the same work as before.

Type of change:

  • Improvement

High-level design:

N/A, small change: one SPI, its run-scoped composite, and the workflow calls main already has.

Tests:

Use cases covered

  • A Data Insights run with no provider writes the same documents as before.
  • A provider's session prepares each batch before enrichment, enriches every snapshot document, and completes only after a successful run. Cancellation stops enrichment and completion.
  • A provider that fails to start, returns a null session or fails to close does not leak the sessions already opened.

Unit tests

  • DataInsightsExtensionsTest, from main. One case changes: on 2.0 it asserts that the composite writes nothing of its own to a snapshot, only what the sessions add.
  • On 2.0 @ ab670ac85a6, mvn install -pl openmetadata-service -am -Dtest='DataInsightsExtensionsTest,DataAssetsWorkflowConcurrencyTest' ran 7 tests with 0 failures.
  • Google Java Format passed (pre-commit).

Backend integration tests

  • Not applicable (no API change). The Data Insights ITs (DataInsightsEnricherBehaviorIT, EnricherBulkVsHistoryPathEquivalenceIT) run the workflow and were not run locally; CI runs them.

Ingestion integration tests

  • Not applicable (no ingestion changes).

Playwright (UI) tests

  • Not applicable (no UI changes).

Manual testing performed

  • A downstream extension built against this branch compiles, and its 7 unit tests pass against this build.
  • Not run: a Data Insights run on a deployed 2.0 instance with a provider registered.

UI screen recording / screenshots:

Not applicable.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>: a backport of feat(data-insights): capture completeness evidence and extend run lifecycle #33079, no separate issue.
  • My PR is linked to a GitHub issue via Fixes #<issue-number> above: same reason.
  • I have commented on my code, particularly in hard-to-understand areas.
  • For JSON Schema changes: no schema change.
  • For UI changes: no UI change.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.

🤖 Generated with Claude Code

Backports the extension hook from #33079 to 2.0, without the completeness
evidence that PR also adds: DataInsightsExtension (a ServiceLoader SPI with
run-scoped sessions), DataInsightsExtensions (opens every provider for a run,
closes them on failure) and the DataAssetsWorkflow calls (beforeBatch, enrich on
each snapshot document, complete after a successful run).

Unlike main, the 2.0 hook writes no diRunId/diCapturedAt stamp of its own: 2.0's
index template has no mapping for them, so they would surface as new Data
Insights fields on every document. With no provider registered, a run behaves as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pmbrull
pmbrull requested a review from a team as a code owner November 14, 2026 17:21
@pmbrull
pmbrull requested review from sonika-shah and removed request for a team November 14, 2026 17:21
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

continue;
}

extensions.beforeBatch(batch.getData());

@gitar-bot gitar-bot Bot Nov 14, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Edge Case: Cancellation in beforeBatch skips the per-source stats update

extensions.beforeBatch(...) (line 316) calls requireActive(), which throws CancellationException if stop() ran between batches or if the thread was left interrupted after the InterruptedException branch at line 372, which only breaks out of the current source. The inner try only catches SearchIndexException and InterruptedException, so the exception goes straight out of processSource. That skips the trailing drainAndFlush/updateWorkflowStats/mergeEnricherStepStats block (lines 381-386), and process() swallows the exception at line 247. Before this change, a stop inside a source still ended the loop normally and recorded that source's stats. With this change, they are lost on cancellation even when no extension is registered, since requireActive() runs no matter how many sessions exist. Fix: catch CancellationException inside the batch loop (mark it stopped and break), or check stopped instead of calling requireActive() before the batch.

Treat cancellation from the extension hook as a normal stop so the per-source finalisation still runs.:

} catch (CancellationException ex) {
  stopped = true;
  break;
} catch (InterruptedException ex) {
  Thread.currentThread().interrupt();
  break;
}

Was this helpful? React with 👍 / 👎

@gitar-bot

gitar-bot Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Code Review 👍 Approved with suggestions 🟡 Medium risk 0 closed / 1 findings

The new ServiceLoader hook lets providers alter indexed Data Insights snapshots, so faulty enrichment could write incorrect fields or disrupt runs.

Adds the DataInsightsExtension SPI and a run-scoped DataInsightsExtensions composite, wired into DataAssetsWorkflow around batch enrichment, so a distribution can add fields to Data Insights snapshots without patching the workflow. No provider is registered in OSS, so existing runs are unchanged.

  • Open (minor): beforeBatch calls requireActive() inside the batch loop, so a cancellation throws CancellationException and skips the trailing per-source stats update and drainAndFlush in DataAssetsWorkflow.processSource. Suggested fix: catch CancellationException in the batch loop and break, or check stopped instead of calling requireActive() before each batch.
💡 Edge Case: Cancellation in beforeBatch skips the per-source stats update

📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataAssetsWorkflow.java:316 📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataAssetsWorkflow.java:365-379 📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataAssetsWorkflow.java:247-249 📄 openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataInsightsExtensions.java:58-61

extensions.beforeBatch(...) (line 316) calls requireActive(), which throws CancellationException if stop() ran between batches or if the thread was left interrupted after the InterruptedException branch at line 372, which only breaks out of the current source. The inner try only catches SearchIndexException and InterruptedException, so the exception goes straight out of processSource. That skips the trailing drainAndFlush/updateWorkflowStats/mergeEnricherStepStats block (lines 381-386), and process() swallows the exception at line 247. Before this change, a stop inside a source still ended the loop normally and recorded that source's stats. With this change, they are lost on cancellation even when no extension is registered, since requireActive() runs no matter how many sessions exist. Fix: catch CancellationException inside the batch loop (mark it stopped and break), or check stopped instead of calling requireActive() before the batch.

Treat cancellation from the extension hook as a normal stop so the per-source finalisation still runs.
} catch (CancellationException ex) {
  stopped = true;
  break;
} catch (InterruptedException ex) {
  Thread.currentThread().interrupt();
  break;
}
🤖 Prompt for agents
Code Review: Adds the `DataInsightsExtension` SPI and a run-scoped `DataInsightsExtensions` composite, wired into `DataAssetsWorkflow` around batch enrichment, so a distribution can add fields to Data Insights snapshots without patching the workflow. No provider is registered in OSS, so existing runs are unchanged.
  
  - Open (minor): `beforeBatch` calls `requireActive()` inside the batch loop, so a cancellation throws `CancellationException` and skips the trailing per-source stats update and `drainAndFlush` in `DataAssetsWorkflow.processSource`. Suggested fix: catch `CancellationException` in the batch loop and break, or check `stopped` instead of calling `requireActive()` before each batch.

1. 💡 Edge Case: Cancellation in beforeBatch skips the per-source stats update
   Files: openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataAssetsWorkflow.java:316, openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataAssetsWorkflow.java:365-379, openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataAssetsWorkflow.java:247-249, openmetadata-service/src/main/java/org/openmetadata/service/apps/bundles/insights/workflows/dataAssets/DataInsightsExtensions.java:58-61

   `extensions.beforeBatch(...)` (line 316) calls `requireActive()`, which throws `CancellationException` if `stop()` ran between batches or if the thread was left interrupted after the `InterruptedException` branch at line 372, which only breaks out of the current source. The inner try only catches `SearchIndexException` and `InterruptedException`, so the exception goes straight out of `processSource`. That skips the trailing `drainAndFlush`/`updateWorkflowStats`/`mergeEnricherStepStats` block (lines 381-386), and `process()` swallows the exception at line 247. Before this change, a stop inside a source still ended the loop normally and recorded that source's stats. With this change, they are lost on cancellation even when no extension is registered, since `requireActive()` runs no matter how many sessions exist. Fix: catch `CancellationException` inside the batch loop (mark it stopped and break), or check `stopped` instead of calling `requireActive()` before the batch.

   Fix (Treat cancellation from the extension hook as a normal stop so the per-source finalisation still runs.):
   } catch (CancellationException ex) {
     stopped = true;
     break;
   } catch (InterruptedException ex) {
     Thread.currentThread().interrupt();
     break;
   }

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@pmbrull
pmbrull merged commit 58eacc7 into 2.0 Nov 15, 2026
60 of 68 checks passed
@pmbrull
pmbrull deleted the backport/2.0/data-insights-extension-hook branch November 15, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant